<?php
/**
 * Exstension for MyArcadePlugin
 *
 * This file extends WPSocialStreamer to support GD Star Rating actions
 *
 * @package WPSocialStreamer
 * @subpackage ExstensionWordPress
 */
 
// No direct access!
if ( !defined('ABSPATH') ) exit;

// Register needed actions
add_action( 'gdsr_vote_rating_article', 'wpsocialstreamer_gd_star_rating_vote_article', 10, 3);
add_action( 'gdsr_vote_thumb_article', 'wpsocialstreamer_gd_star_rating_vote_article', 10, 3);
// Add extension options filter 
add_filter( 'wpsocialstreamer_extensions', 'wpsocialstreamer_extension_gd_star_rating_settings' );

/**
 * Extend the extension array
 * 
 * @param type $extensions_array
 * @return type
 */
function wpsocialstreamer_extension_gd_star_rating_settings( $extensions_array ) {
  
  $extensions_array['gd_star_rating'] = array (
    /* Set the title that will be displayed on the settings page */
    'title'     => __('GD Star Rating', 'wpsocialstreamer'),
    /* Set a function that should be used to checked if the plugin is installed */
    'function'	=> 'wp_gdsr_render_rating_results',
    /* Set the link to the plugin */
    'link'		=> 'http://www.dev4press.com/plugins/gd-star-rating/',
    /* Extension status */
    'active' => false,
    /* Define an array with available events / actions */
    /* ATTENTION: events should be named exactly like the corresponding action! */      
    'events' => array (
      'gdsr_vote_rating_article'  => array (
        /* Set the default message template */
        'template'  => __('Hey, I just rated "%POST_NAME%"!', 'wpsocialstreamer'),
        /* Set the event description for user settings page. */
        /* Share this event when: */
        'title'     => __("I rate a post.", 'wpsocialstreamer'),
        /* Define some placeholders that admins can use to generate message text */
        /* Set to false if no placeholders are available: 'placeholders' => false */
        'placeholders' => array ( 
          /* Set placeholder name and a short description */
          'POST_NAME' => __("Name of the post", 'wpsocialstreamer'),
          'VOTE'      => __("User rating", 'wpsocialstreamer')
        ) /* END placeholders */
      ) /* END event */
    ) /* END events */
  );
    
  return $extensions_array;
}

/**
 * Called when user rates a post
 */
function wpsocialstreamer_gd_star_rating_vote_article( $postID, $user, $votes ) {
  global $wpss;
   
  // Check if extension event is active
  if ( $wpss->is_active( 'gd_star_rating', 'gdsr_vote_rating_article' ) ) {
      
    $wpss->set_raw_message( 'gd_star_rating', 'gdsr_vote_rating_article' );
  
    // Generate data that should be shared
    $wpss->set_data( array (
        'POST_NAME' => get_the_title($postID),
        'VOTE'      => $votes,
        /* Every extension must contain the LINK field. Values: link or false */
        'LINK'   => get_permalink( $postID )   
      )
    );
    
    // Generate and share the message
    $wpss->generate_and_share();
  }
}
?>